from config import URL
import logging

class RegLoginApi(object):

    def __init__(self, session):
        self.session = session

    # 获取图片验证码接口
    def get_img_verify_code(self, r):
        url = URL + "/common/public/verifycode1/{}".format(r)
        response = self.session.get(url=url)
        print("获取图片验证码接口返回的状态码:{}".format(response.status_code))
        return response

    # 获取短信验证码接口
    def get_phone_verify_code(self, phone_v, imgverifycode_v, type_v):
        url = URL + "/member/public/sendSms"
        # 定义一个字典的变量,用来接收请求体的数据
        form_dict = {'phone': phone_v, 'imgVerifyCode': imgverifycode_v, 'type': type_v}
        # 实现接口请求,获取接口返回的相应数据
        response = self.session.post(url=url, data=form_dict)
        print("获取短信验证码接口的响应体数据:{}".format(response.json()))
        logging.info("获取短信验证码接口的响应体数据:{}".format(response.json()))
        return response

    # 注册接口
    def user_register(self, phone_v, pwd_v, verifyCode_v, phoneCode_v, dyServer_v, invitePhone_v):
        url = URL + "/member/public/reg"
        # 定义一个字典的变量,用来接收请求体的数据
        form_dict = {'phone': phone_v,
                     'password': pwd_v,
                     'verifycode': verifyCode_v,
                     'phone_code': phoneCode_v,
                     'dy_server': dyServer_v,
                     'invite_phone': invitePhone_v
                     }
        # 实现接口请求,获取接口返回的相应数据
        response = self.session.post(url=url, data=form_dict)
        print("注册接口的响应体数据:{}".format(response.json()))
        logging.info("注册接口的响应体数据:{}".format(response.json()))
        return response

    # 登录接口
    def user_login(self, keywords_v, pwd_v):
        url = URL + "/member/public/login"
        # 定义一个字典的变量,用来接收请求体的数据
        form_dict = {'keywords': keywords_v, 'password': pwd_v}
        # 实现接口请求,获取接口返回的相应数据
        response = self.session.post(url=url, data=form_dict)
        print("登录接口的响应体数据:{}".format(response.text))
        logging.info("登录接口的响应体数据:{}".format(response.text))
        return response
